﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Billing.DataObjects;

namespace Billing.Transactions
{
    public partial class PeriodCloseForm : Billing.WindowsBase.FormBase
    {
        public PeriodCloseForm()
        {
            InitializeComponent();
        }

        BillingDataContext mBillingDataContext;
        public BillingDataContext BillingDataContext
        {
            get
            {
                if (mBillingDataContext == null)
                    mBillingDataContext = new BillingDataContext();
                return mBillingDataContext;
            }
            set { mBillingDataContext = value; }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void PeriodCloseForm_Load(object sender, EventArgs e)
        {
            this.dtClosedPeriodDate.Value = (DateTime)this.BillingDataContext.GetClosedPeriod();
        }

        private void btnCloseCurrentPeriod_Click(object sender, EventArgs e)
        {
            try
            {
                if (ShowQuestion("დავხურო პერიოდი?") == DialogResult.Yes)
                {
                    this.BillingDataContext.CommandTimeout = 600;
                    this.BillingDataContext.PeriodClose();
                    ShowInformation("პერიოდი დახურულია");
                }
            }
            catch (Exception ex)
            {
                ShowError(ex);
            }
        }
    }
}
